package com.xiaotao.controller;

import com.xiaotao.entity.Coupon;
import com.xiaotao.entity.CouponRequest;
import com.xiaotao.entity.UserCoupon;
import com.xiaotao.service.UserCouponService;
import com.xiaotao.util.ResponseUtil;
import com.xiaotao.util.UserUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/userCoupon")
public class UserCouponController {
    @Resource
    private UserCouponService userCouponService;

    @GetMapping
    public ResponseUtil queryAll() {
        return userCouponService.queryAll();
    }

    @PostMapping
    public ResponseUtil add(@RequestBody CouponRequest couponRequest) throws Exception {
        Integer id = couponRequest.getId();
        return userCouponService.add(id);
    }

    @GetMapping("/userId")
    public ResponseUtil queryByUserId() throws Exception {
        Integer userId = UserUtil.UserContext();
        return userCouponService.queryByUserId(userId);
    }
}
